package com.example.demo.Controller;

import com.example.demo.core.NotFoundException;
import com.example.demo.core.Response;
import com.example.demo.core.security.JWTUtil;
import com.example.demo.model.BookBorrow;
import com.example.demo.service.AdminService;
import com.example.demo.service.BookBorrowAndFeeService;
import com.example.demo.service.BookService;
import com.example.demo.service.UserService;
import com.sun.javafx.collections.MappingChange;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/statistic")
public class StatisticController {

    @Autowired
    BookService bookServiceImpl;

    @Autowired
    BookBorrowAndFeeService bookBorrowAndFeeServiceImp;

    @Autowired
    AdminService adminService;

    @Autowired
    UserService userService;

    @GetMapping("/info")
    @RequiresAuthentication
    public Object selectInfo(HttpServletRequest request) throws NotFoundException {

        Map<String, Integer> resultMap=new HashMap();

        resultMap.put("userNumber",userService.selectByCondition(null,null,null,null).size());
        resultMap.put("bookNumber",bookServiceImpl.selectByCondition(null,null,null,null,null,null,null,null).size());
        resultMap.put("borrowNumber",bookBorrowAndFeeServiceImp.selectBorrowRecord(null,null).size());

        return Response.ok(resultMap);
    }
}
